<?php
defined('BY_JYA') or exit('error');
$_RQ['op']=$_RQ['op']?$_RQ['op']:'list';
$return=array();
$tabs=array(
	array('op'=>'list','title'=>'月度排行榜'),
	array('op'=>'yearlist','title'=>'年度排行榜'),
);
set_html('tabs',$tabs);
if($_RQ['op']=='list'){
	$params=array('uniacid'=>$_SESSION['uniacid'],'is_agent >'=>0);
	$month_start=strtotime(date('Ym').'01');
	if($_RQ['mid']){
		$params['mid']=intval($_RQ['mid']);
		$return['params']['mid']=$_RQ['mid'];
	}
	if(isset($_RQ['status'])){
		$params['status']=intval($_RQ['status']);
		$return['params']['status']=$_RQ['status'];
	}
	if($_RQ['ordersn']){
		$params['ordersn']=$_RQ['ordersn'];
		$return['params']['ordersn']=$_RQ['ordersn'];
	}
	$psize=10;
	$pindex=intval($_RQ['page'])?:1;
	$parameter=array(
		'params'=>$params,
		'limit'=>array($pindex,$psize),
		'orderby'=>'order_price desc,mid desc',
	);
	$list=$this->get_list('member',$parameter,$total);
	if($list){
		foreach($list as $k=>&$item){
			$item['member']=cfc('core')->member_show($item['mid']);
			$paiming=$k+1;
			$item['paiming']='第'.$paiming.'名';
		}
	}
	$return['list']=$list;
	$totalpage=ceil($total/$psize);
	$totalpage=intval($totalpage);
	$return['totalpage'] =$totalpage;
	$return['params']['page'] =$pindex;
	$htmls=array(
		'type'=>'list',
		'list'=>array(
			'tip'=>'排行榜满额后，触发发放条件！',
			'data'=>'list','edit'=>false,'del_one'=>false,'delall'=>false,'list'=>array(
			array('name'=>'paiming','title'=>'排名','type'=>'string'),
			array('name'=>'member','title'=>'店主信息','type'=>'member'),
			array('name'=>'level_id','title'=>'店主等级','type'=>'select','options'=>'levels'),
			array('name'=>'order_price','title'=>'销售额','type'=>'string'),
		)),
		'search'=>array(
			array('type'=>'choose','width'=>15,'action'=>'core/member.get_member/','name'=>'mid','title'=>'选择会员'),
		),
	);
	$return['htmls']=$htmls;
	$return['levels']=$this->getall('level',array('uniacid'=>$_SESSION['uniacid']),array('id','title'),'id');
	$return['levels']['0']=array('id'=>'0','title'=>'默认等级');
	$return['feechi_status']=$this->feechi_status;
	$return['isadd_type']=$this->isadd_type;
	exi($return);
}
if($_RQ['op']=='yearlist'){
	$params=array('uniacid'=>$_SESSION['uniacid'],'is_agent >'=>0);
	$month_start=strtotime(date('Ym').'01');
	if($_RQ['mid']){
		$params['mid']=intval($_RQ['mid']);
		$return['params']['mid']=$_RQ['mid'];
	}
	if(isset($_RQ['status'])){
		$params['status']=intval($_RQ['status']);
		$return['params']['status']=$_RQ['status'];
	}
	if($_RQ['ordersn']){
		$params['ordersn']=$_RQ['ordersn'];
		$return['params']['ordersn']=$_RQ['ordersn'];
	}
	$psize=$this->setting['month_num']?:10;
	$pindex=intval($_RQ['page'])?:1;
	$parameter=array(
		'params'=>$params,
		'limit'=>array($pindex,$psize),
		'orderby'=>'order_price desc,mid desc',
	);
	$list=$this->get_list('member',$parameter,$total);
	if($list){
		foreach($list as $k=>&$item){
			$item['member']=cfc('core')->member_show($item['mid']);
			$paiming=$k+1;
			$item['paiming']='第'.$paiming.'名';
		}
	}
	$return['list']=$list;
	$totalpage=ceil($total/$psize);
	$totalpage=intval($totalpage);
	$return['totalpage'] =$totalpage;
	$return['params']['page'] =$pindex;
	$htmls=array(
		'type'=>'list',
		'list'=>array(
			'tip'=>'排行榜慢额后，触发发放条件！',
			'data'=>'list','edit'=>false,'del_one'=>false,'delall'=>false,'list'=>array(
			array('name'=>'paiming','title'=>'排名','type'=>'string'),
			array('name'=>'member','title'=>'店主信息','type'=>'member'),
			array('name'=>'level_id','title'=>'店主等级','type'=>'select','options'=>'levels'),
			array('name'=>'order_price','title'=>'销售额','type'=>'string'),
		)),
		'search'=>array(
			array('type'=>'choose','width'=>15,'action'=>'core/member.get_member/','name'=>'mid','title'=>'选择会员'),
		),
	);
	$return['htmls']=$htmls;
	$return['levels']=$this->getall('level',array('uniacid'=>$_SESSION['uniacid']),array('id','title'),'id');
	$return['levels']['0']=array('id'=>'0','title'=>'默认等级');
	$return['feechi_status']=$this->feechi_status;
	$return['isadd_type']=$this->isadd_type;
	exi($return);
}
if($_RQ['op']=='detail'){
	$item=$this->get('feechi',array('id'=>intval($_RQ['id'])),array('id','remark'));
	if(!$item){
		exi('指定佣金不存在！','error');
	}
	$item['remark']=$this->model('commission')->commission_remark($item['remark']);
	$return['item']=$item;
	$return['htmls']=array(
		'type'=>'look',
		'desc'=>'佣金明细',
		'look'=>array(
			array('type'=>'text','name'=>'remark','title'=>'佣金明细'),
		),
	);
	exi($return);
}